package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.factoryattendance.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2024/3/22 13:48
 * 部装信息列表 适配器
 */
public class UnitInfoAdapter extends BaseAdapter {
    private Context context;
    private List<List<String>> unitListItem;

    public UnitInfoAdapter(Context context, List<List<String>> orderListItem) {
        this.context = context;
        this.unitListItem = orderListItem;
    }

    @Override
    public int getCount() {
        return unitListItem == null ? 0 : unitListItem.size();
    }

    @Override
    public Object getItem(int position) {
        return unitListItem == null ? null : unitListItem.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        UnitInfoAdapter.ViewHolder holder;
        if (rowView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rowView = inflater.inflate(R.layout.unit_info_list, parent, false);
            holder = new UnitInfoAdapter.ViewHolder();
            holder.unitName_TV = rowView.findViewById(R.id.unitName_TV);
            holder.estimatedHours_TV = rowView.findViewById(R.id.estimatedHours_TV);
            holder.creationTime_TV = rowView.findViewById(R.id.creationTime_TV);
            holder.actualHours_TV = rowView.findViewById(R.id.actualHours_TV);
//            holder.productStatus_TV = rowView.findViewById(R.id.productStatus_TV);
            rowView.setTag(holder);
        } else {
            holder = (UnitInfoAdapter.ViewHolder) rowView.getTag();
        }

        List<String> orderShowItem = unitListItem.get(position);
        if (orderShowItem != null) {
            if (orderShowItem.size() >= 4) {
                holder.unitName_TV.setText(orderShowItem.get(0));
                holder.estimatedHours_TV.setText(orderShowItem.get(1));
                holder.creationTime_TV.setText(orderShowItem.get(2));
                holder.actualHours_TV.setText(orderShowItem.get(3));
//            holder.productStatus_TV.setText(orderShowItem.get(4));
            }
        }

        if (position % 2 == 0){
            rowView.setBackgroundColor(Color.parseColor("#FFFFFF"));
        }else {
            rowView.setBackgroundColor(Color.parseColor("#F0FFFF"));
        }
        return rowView;
    }
    private static class ViewHolder {
        TextView unitName_TV;
        TextView estimatedHours_TV;
        TextView creationTime_TV;
        TextView actualHours_TV;
        TextView productStatus_TV;
    }
}
